import 'dart:io';

import 'package:path_provider/path_provider.dart';

Future<String> get _localPath async {
  final directory = await getApplicationDocumentsDirectory();
  return directory.path;
}

// 创建对文件位置的引用
Future<File> get _localFile async {
  final path = await _localPath;
  return new File('$path/counter.txt');
}

// 将数据写入文件
Future<File> writeCounter(String userId) async {
  final file = await _localFile;
  // Write the file
  return file.writeAsString('$userId');
}

// 从文件中读取数据
Future<String> readCounter() async {
  try {
    final file = await _localFile;
    // Read the file
    return await file.readAsString();
  } catch (e) {
    // If we encounter an error, return 0
    return '';
  }
}

// 创建对文件位置的引用
Future<File> get _localFile1 async {
  final path = await _localPath;
  return new File('$path/counter1.txt');
}

// 将数据写入文件
Future<File> writeCounter1(String username, String password) async {
  final file = await _localFile1;
  // Write the file
  return file.writeAsString('$username--$password');
}

// 从文件中读取数据
Future<String> readCounter1() async {
  try {
    final file = await _localFile1;
    // Read the file
    return await file.readAsString();
  } catch (e) {
    // If we encounter an error, return 0
    return '';
  }
}

// 创建对文件位置的引用
Future<File> get _localFile2 async {
  final path = await _localPath;
  return new File('$path/counter2.txt');
}

// 将数据写入文件
Future<File> writeCounter2(String sign) async {
  final file = await _localFile2;
  // Write the file
  return file.writeAsString('$sign');
}

// 从文件中读取数据
Future<String> readCounter2() async {
  try {
    final file = await _localFile2;
    // Read the file
    return await file.readAsString();
  } catch (e) {
    // If we encounter an error, return 0
    return '';
  }
}

// 创建对文件位置的引用
Future<File> get _localFile3 async {
  final path = await _localPath;
  return new File('$path/counter3.txt');
}

// 将数据写入文件
Future<File> writeCounter3(String sign) async {
  final file = await _localFile3;
  // Write the file
  return file.writeAsString('$sign');
}

// 从文件中读取数据
Future<String> readCounter3() async {
  try {
    final file = await _localFile3;
    // Read the file
    return await file.readAsString();
  } catch (e) {
    // If we encounter an error, return 0
    return '';
  }
}